import cv2 as cv
import numpy as np


def circles_detect_demo(image):
    blured = cv.medianBlur(image,5)
    gray = cv.cvtColor(blured,cv.COLOR_BGR2GRAY)

    circles = cv.HoughCircles(gray,cv.HOUGH_GRADIENT,1,20,param1=50,param2=30,minRadius=0,maxRadius=0)
    circles = np.uint16(np.around(circles))

    for circle in circles[0,:]:
        cv.circle(image,(circle[0],circle[1]),circle[2],(0,255,0),2)
        cv.circle(image,(circle[0],circle[1]),2,(0,0,255),1)
    cv.imshow('lines_detected',image)


src = cv.imread('smarties.png', 1)
cv.namedWindow('demo',cv.WINDOW_AUTOSIZE)
cv.imshow('demo', src)
circles_detect_demo(src)
cv.waitKey(0)
cv.destroyWindow('demo')